// packageJ/consensus_activity/asset/asset.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    text: "",
    type: null,
    reopen: 0,
    integral_name: "",
    point_name: "",
    custom_name: {},
    origin_asset_list :[],

    list: [],
    total_page: 1,
    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let type = Number(options.num);
    this.setData({type});
    this.getData();
    this.getRecord();
  },
  getRecord(page = 1) {
    let _url = "plugin.wise-yuan-trade.frontend.reopen-value.record";
    if(this.data.type==1){
      _url  = 'plugin.wise-yuan-trade.frontend.origin-asset.record';
    }
    app._getNetWork({
      url:app.getNetAddresss(_url),
      data:{page},
      success:resdata=>{
        let {result,data,msg} = resdata.data;
        if(result){
          this.data.total_page = data.last_page;
          this.data.page = data.current_page;
          if(page == 1){
            this.setData({list:data.data})
          }else{
            let list = this.data.list.concat(data.data);
            this.setData({list})
          }
        }else{
          app.tips(msg);
        }
      }
    })
  },
  getData(){
    let _url = "plugin.wise-yuan-trade.frontend.reopen-value.index";
    if(this.data.type==1){
      _url  = 'plugin.wise-yuan-trade.frontend.origin-asset.index';
    }
    app._getNetWork({
      url:app.getNetAddresss(_url),
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          let text = "";
          if (this.data.type == 1) {
            text = data.custom_name.origin_asset_name;
            this.setData({
              origin_asset_list:data.origin_asset_list
            })
          } else {
            text = data.custom_name.reopen_name;
            this.setData({
              integral_name:data.integral_name,
              point_name:data.point_name,
              reopen:data.reopen
            })
          }
          this.setData({
            text,
            custom_name:data.custom_name,
          })
          wx.setNavigationBarTitle({
            title: text,
          })
        }else{
          app.tips(msg);
        }
      }
    })
  },
  goto(e){
    let num = e.currentTarget.dataset.num;
    let name = this.data.type=='1'?'asset':'reopen';
    console.log(name);
    // :to="fun.getUrl('consensus_activity_asset_withdraw',{num:1,name:(type==1?'asset':'reopen')})" 
    wx.navigateTo({
      url: '/packageJ/consensus_activity/asset_withdraw/asset_withdraw?num='+num+'&name='+name,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    this.getRecord(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})